#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <queue>

using namespace std;
using LL = long long;
const int N = 2e5 + 10;
/*
first we can find that if we want to make sum(a[i]) minimum
we can make the a[i] with lower height as large as possible, so if we can use bfs

a[i] = min(s[u]) - s[fa];   u : the son of i,   fa: the father of i
s[i] = s[fa] + a[i]


*/

int n;
int h[N], e[N], ne[N], fa[N], idx;
LL s[N], a[N];
bool st[N];
bool cont;

void add(int a, int b){
    fa[b] = a;

    e[idx] = b;
    ne[idx] = h[a];
    h[a] = idx++;
}

void bfs(int u){
    queue<int> q;
    for(int i = h[u]; ~i; i = ne[i]){
        int j = e[i];
        q.push(j);
    }

    while(!q.empty()){
        int t = q.front();
        q.pop();


        LL num = 1e18 + 10;
        if(s[t] == -1){
            bool flag = false;
            for(int i = h[t]; ~i; i = ne[i]){
                flag = true;
                int j = e[i];
                num = min(s[j], num);
            }

            if(flag){
                a[t] = num - s[fa[t]];
                s[t] = num;

                if(a[t] < 0){
                    cont = false;
                }

            }else{
                a[t] = 0;
            }
        }else{
            a[t] = s[t] - s[fa[t]];
        }

        for(int i = h[t]; ~i; i = ne[i]){
            int j = e[i];
            q.push(j);
        }

    }
}

LL dfs(int u){
    LL res = a[u];
    for(int i = h[u]; ~i; i = ne[i]){
        int j = e[i];
        res += dfs(j);
    }
    return res;
}

void solve(){
    memset(h, -1, sizeof h);
    cont = true;

    cin >> n;
    for(int i = 2, x; i <= n; i ++){
        cin >> x;
        add(x, i);
    }
    
    for(int i = 1; i <= n; i ++){
        cin >> s[i];
    }

    a[1] = s[1];
    bfs(1);

    LL res = dfs(1);
    if(cont){
        cout << res << '\n';
    }else{
        cout << -1 << '\n';
    }
}



int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
    return 0;
}